package cn.trip.biz.service.impl;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.pojo.*;
import cn.itrip.beans.vo.ItripOrderInfoVO;
import cn.itrip.beans.vo.ItripOrderSelect;
import cn.itrip.beans.vo.ItripPersonalHotelOrderVO;
import cn.itrip.beans.vo.ItripPersonalOrderRoomVO;
import cn.itrip.common.Md5Util;
import cn.itrip.common.Page;
import cn.itrip.common.RedisUtil;
import cn.itrip.dao.*;
import cn.trip.biz.service.ItripHotelOrderService;
import com.alibaba.fastjson.JSONArray;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("itripHotelOrderService")
public class ItripHotelOrderServiceImpl implements ItripHotelOrderService {
    @Autowired
    private ItripHotelOrderMapper itripHotelOrderMapper;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private HttpSolrServer httpSolrServer;
    @Autowired
    private ItripHotelRoomMapper itripHotelRoomMapper;
    @Autowired
    private ItripHotelMapper itripHotelMapper;
    @Autowired
    private ItripHotelTempStoreMapper itripHotelTempStoreMapper;
    @Autowired
    private ItripOrderLinkUserMapper itripOrderLinkUserMapper;

    /**
     * 从缓存中拿user对象
     *
     * @param token
     * @return
     */
    @Override
    public ItripUser user(String token) {
        ItripUser user1 = (ItripUser) redisUtil.get(token);
        return user1;
    }

    /**
     * 订单列表（模糊）
     *
     * @param itripOrderSelect
     * @return
     */
    @Override
    //redis主键为order+用户Id+每一个查询条件的值
    public Dto<Page> selectByUserId(ItripOrderSelect itripOrderSelect) throws SolrServerException {
        Dto<Page> dto = new Dto();
        Page<ItripHotelOrder> page = new Page<>();
        StringBuffer key = new StringBuffer("order:userId=" + itripOrderSelect.getUserId());

//        SolrQuery query=new SolrQuery("*:*");

        if (itripOrderSelect.getOrderType() == -1) {
            itripOrderSelect.setOrderType(null);
        } else {
            key.append("orderType=" + itripOrderSelect.getOrderType().toString());
//            query.setQuery("orderType:"+itripOrderSelect.getOrderType());
        }
        if (itripOrderSelect.getOrderStatus() == -1) {
            itripOrderSelect.setOrderStatus(null);
        } else {
            key.append("orderStatus=" + itripOrderSelect.getOrderStatus().toString());
//            query.setQuery("orderStatus="+itripOrderSelect.getOrderStatus());
        }

        if (itripOrderSelect.getLinkUserName() != null && !itripOrderSelect.getLinkUserName().equals("")) {
            key.append("linkUserName=" + itripOrderSelect.getLinkUserName());
//            query.setQuery("linkUserName=*"+itripOrderSelect.getLinkUserName());
        }
        if (itripOrderSelect.getOrderNo() != null && !itripOrderSelect.getOrderNo().equals("")) {
            key.append("orderNo=" + itripOrderSelect.getOrderNo());
//            query.setQuery("orderNo=*"+itripOrderSelect.getOrderNo());
        }
        if (itripOrderSelect.getStartDate() != null && !itripOrderSelect.getStartDate().equals("")) {
            key.append("creationDateMin=" + itripOrderSelect.getStartDate().toString());
//            query.setQuery("orderNo>"+itripOrderSelect.getStartDate());
        }
        if (itripOrderSelect.getEndDate() != null && !itripOrderSelect.getEndDate().equals("")) {
            key.append("creationDateMax=" + itripOrderSelect.getEndDate().toString());
//            query.setQuery("orderNo <"+itripOrderSelect.getEndDate());
        }
//        query.setStart(itripOrderSelect.getPageNo());
//        key.append("start=" + itripOrderSelect.getPageNo());
//        query.setRows(itripOrderSelect.getPageSize());
//        key.append("rows=" + itripOrderSelect.getPageSize());

        List<ItripHotelOrder> order = null;
        int totalCount = selectCount(itripOrderSelect);
        List<ItripHotelOrder> list = new ArrayList<>();
        if (redisUtil.get(key.toString()) == null) {
            order = itripHotelOrderMapper.selectByUserId(itripOrderSelect);
//            QueryResponse queryResponse=httpSolrServer.query(query);
//            order=queryResponse.getBeans(ItripHotelOrder.class);
//           List<T> list1= queryResponse.getResults();
            if (order != null) {
                redisUtil.set(key.toString(), order, 600);
                dto.setSuccess("true");
                dto.setErrorCode("0");
            } else {
                dto.setSuccess("false");
                dto.setMsg("当前用户没有任何订单消息");
                return dto;
            }
        } else {
            order = (List<ItripHotelOrder>) redisUtil.get(key.toString());
            dto.setSuccess("true");
            dto.setErrorCode("0");

        }
        for (int i = itripOrderSelect.getPageNo(); i < (itripOrderSelect.getPageNo() + itripOrderSelect.getPageSize()); i++) {
            if (i < order.size()) {
                list.add(order.get(i));
            }
        }
        //集合
        page.setRows(list);
        //一页几条
        page.setPageSize(itripOrderSelect.getPageSize());
        //当前页
        page.setCurPage((itripOrderSelect.getPageNo() / itripOrderSelect.getPageSize()) + 1);
        //总条数
        page.setTotal(totalCount);
        dto.setSuccess("true");
        dto.setErrorCode("0");
        dto.setData(page);
        return dto;
    }

    /**
     * 订单总条数
     * redisKey count:+用户Id
     *
     * @param itripOrderSelect
     * @return
     */
    //总计录数,redis主键为count:+用户Id
    @Override
    public int selectCount(ItripOrderSelect itripOrderSelect) {
        Integer integer = null;
        StringBuffer key = new StringBuffer("count:userId=" + itripOrderSelect.getUserId());


        if (itripOrderSelect.getOrderType() != null) {
            key.append("orderType=" + itripOrderSelect.getOrderType().toString());
        }
        if (itripOrderSelect.getOrderStatus() != null) {
            key.append("orderStatus=" + itripOrderSelect.getOrderStatus().toString());
        }

        if (itripOrderSelect.getLinkUserName() != null && !itripOrderSelect.getLinkUserName().equals("")) {
            key.append("linkUserName=" + itripOrderSelect.getLinkUserName());
        }
        if (itripOrderSelect.getOrderNo() != null && !itripOrderSelect.getOrderNo().equals("")) {
            key.append("orderNo=" + itripOrderSelect.getOrderNo());
        }
        if (itripOrderSelect.getStartDate() != null && !itripOrderSelect.getStartDate().equals("")) {
            key.append("creationDateMin=" + itripOrderSelect.getStartDate().toString());
        }
        if (itripOrderSelect.getEndDate() != null && !itripOrderSelect.getEndDate().equals("")) {
            key.append("creationDateMax=" + itripOrderSelect.getEndDate().toString());
        }


        if (redisUtil.get(key.toString()) == null) {
            integer = itripHotelOrderMapper.selectCount(itripOrderSelect);
            redisUtil.set(key.toString(), integer, 600);
        } else {
            integer = (Integer) redisUtil.get(key.toString());
        }
        return integer;
    }

    /**
     * 订单详情
     * redis
     *
     * @param id
     * @return
     */
    @Override
    public Dto<ItripHotelOrder> selectDetailByidFromRedis(Long id, String redisOrderKey) {
        Dto dto = new Dto();
        ItripHotelOrder itripHotelOrder = null;
        ItripPersonalHotelOrderVO itripPersonalHotelOrderVO = new ItripPersonalHotelOrderVO();
        if (redisUtil.hasKey(redisOrderKey)) {
            List<ItripHotelOrder> list = (List<ItripHotelOrder>) redisUtil.get(redisOrderKey);
            for (ItripHotelOrder order : list) {
                if (order.getId().equals(id)) {
                    itripHotelOrder = order;
                    break;
                }
            }
            if (itripHotelOrder == null) {
                dto.setSuccess("false");
                dto.setMsg("没有当前订单id");
                return dto;
            }
        } else {
            itripHotelOrder = selectByPrimaryKey(id);
        }
        if (itripHotelOrder != null) {
            itripPersonalHotelOrderVO.setId(itripHotelOrder.getId());
            itripPersonalHotelOrderVO.setBookType(itripHotelOrder.getBookType());
            itripPersonalHotelOrderVO.setCreationDate(itripHotelOrder.getCreationDate());
            itripPersonalHotelOrderVO.setOrderNo(itripHotelOrder.getOrderNo());
            ItripHotelRoom room = selectById(itripHotelOrder.getRoomId());

            if (room != null) {
                itripPersonalHotelOrderVO.setRoomPayType(room.getPayType());
            }
            Integer orderStatus = itripHotelOrder.getOrderStatus();
            itripPersonalHotelOrderVO.setOrderStatus(orderStatus);
            if (orderStatus == 1) {
                itripPersonalHotelOrderVO.setProcessNode("3");
            } else if (orderStatus == 0) {
                itripPersonalHotelOrderVO.setProcessNode("2");//订单支付
            } else if (orderStatus == 2) {
                itripPersonalHotelOrderVO.setProcessNode("3");//支付成功（未出行）
            } else if (orderStatus == 3) {
                itripPersonalHotelOrderVO.setProcessNode("5");//订单点评
            } else if (orderStatus == 4) {
                itripPersonalHotelOrderVO.setProcessNode("6");//订单完成
            } else {
                itripPersonalHotelOrderVO.setOrderProcess(null);
                itripPersonalHotelOrderVO.setProcessNode(null);
            }
            itripPersonalHotelOrderVO.setPayAmount(itripHotelOrder.getPayAmount());
            itripPersonalHotelOrderVO.setPayType(itripHotelOrder.getPayType());
            itripPersonalHotelOrderVO.setNoticePhone(itripHotelOrder.getNoticePhone());
        } else {
            dto.setSuccess("false");
            dto.setMsg("没有当前订单id");
            return dto;
        }
        dto.setSuccess("true");
        dto.setErrorCode("0");
        dto.setData(itripPersonalHotelOrderVO);
        return dto;
    }

    /**
     * 根据订单id查详情
     *
     * @param id
     * @return
     */
    @Override
    public ItripHotelOrder selectByPrimaryKey(Long id) {
        return itripHotelOrderMapper.selectByPrimaryKey(id);
    }

    /**
     * redisKey room:id
     *
     * @param id
     * @return
     */
    @Override
    public ItripHotelRoom selectById(Long id) {
        StringBuffer sb = new StringBuffer("room:" + id);
        ItripHotelRoom itripHotelRoom = null;
        if (redisUtil.hasKey(sb.toString())) {
            itripHotelRoom = (ItripHotelRoom) redisUtil.get(sb.toString());
        } else {
            itripHotelRoom = itripHotelRoomMapper.selectByPrimaryKey(id);
            redisUtil.set(sb.toString(), itripHotelRoom);
        }
        return itripHotelRoom;
    }

    /**
     * 根据订单id删除订单
     *
     * @param id
     * @return
     */
    @Override
    public Dto deleteByPrimaryKey(Long id) {
        Dto dto = new Dto();
        int i = itripHotelOrderMapper.deleteByPrimaryKey(id);
        if (i != 0) {
            dto.setSuccess("true");
            if (redisUtil.hasPreKey("order:*")) {
                redisUtil.deletePrefix("order:*");
            }
            if (redisUtil.hasPreKey("count:*")) {
                redisUtil.deletePrefix("count:*");
            }
        } else {
            dto.setSuccess("false");
            dto.setMsg("订单删除失败");
        }
        return dto;
    }

    @Override
    public Dto<ItripPersonalOrderRoomVO> getItripHotelOrderRoomInfoById(Long id) {
        Dto<ItripPersonalOrderRoomVO> dto = new Dto<>();
        ItripPersonalOrderRoomVO itripPersonalOrderRoomVO = itripHotelOrderMapper.getItripHotelOrderRoomInfoById(id);
        if (itripPersonalOrderRoomVO != null) {
            dto.setErrorCode("0");
            dto.setSuccess("true");
            dto.setData(itripPersonalOrderRoomVO);
        } else {
            dto.setSuccess("false");
            dto.setMsg("暂无住房信息");
        }
        return dto;
    }

    /**
     * redisKey1 (酒店详情) hotelDetail:hotelId
     * redisKey(房间) hotelRoom:hotelId=hotelIdroomId=roomId
     * redisKey(实时库存) tempStore：hotelId= roomId= checkInDate= checkOutDate=
     *
     * @param itripOrderInfoVO
     * @param token
     * @return
     */
    @Override
    public Dto getOrderInfo(ItripOrderInfoVO itripOrderInfoVO, String token) {
        Dto dto = new Dto();
        //要做的事情：1、拿到用户对象；2、根据hotelId取得酒店信息；3、根据roomId取得房间信息；4、得到实时库存
        ItripUser user = (ItripUser) redisUtil.get(token);

        String key = "hotelDetail:hotelId=" + itripOrderInfoVO.getHotelId();
        ItripHotel hotel;
        if (redisUtil.hasKey(key)) {
            hotel = (ItripHotel) redisUtil.get(key);
        } else {
            hotel = itripHotelMapper.selectByPrimaryKey(itripOrderInfoVO.getHotelId());
        }

        String key2 = "hotelRoom:hotelId=" + itripOrderInfoVO.getHotelId() + "roomId=" + itripOrderInfoVO.getRoomId();
        ItripHotelRoom room;
        if (redisUtil.hasKey(key2)) {
            room = (ItripHotelRoom) redisUtil.get(key2);
        } else {
            room = itripHotelRoomMapper.selectByPrimaryKey(itripOrderInfoVO.getRoomId());
        }

        List<ItripHotelTempStore> tempStore = itripHotelTempStoreMapper.getTempStore(itripOrderInfoVO);

        itripOrderInfoVO.setHotelName(hotel.getHotelName());
        itripOrderInfoVO.setPrice(room.getRoomPrice());
        if (tempStore == null || tempStore.size() == 0) {
            dto.setSuccess("false");
            dto.setMsg("暂无房间");
            return dto;
        }
        if (tempStore.get(0).getStore() == null || tempStore.get(0).getStore() < 0) {
            itripOrderInfoVO.setStore(0);
        } else {
            itripOrderInfoVO.setStore(tempStore.get(0).getStore());
        }
        dto.setSuccess("true");
        dto.setErrorCode("0");
        dto.setData(itripOrderInfoVO);
        return dto;
    }


    @Override
    public boolean updateStatusByScheduled(int status) {
        int flag = 0;
        if (status == 1) {
            //针对未支付订单，如果当前时间-创建时间>10=分钟，状态变为已取消
            flag = itripHotelOrderMapper.updateStatusUnpayToCancel();
        } else {
            //针对支付成功，如果当前时间>退房时间，状态变为已消费。库存数量加上相应的房间数
            List<ItripHotelOrder> list = itripHotelOrderMapper.getStatus2StoreSum(2);
            if (list != null || list.size() != 0) {
                for (ItripHotelOrder itripHotelOrder : list) {
                    itripHotelTempStoreMapper.updateStore(itripHotelOrder);
                }
            }
            flag = itripHotelOrderMapper.updateStatusSuccessToconsumption();
        }
        if (flag == 0) {
            if (redisUtil.hasPreKey("order:*")) {
                redisUtil.deletePrefix("order:*");
            }
            if (redisUtil.hasPreKey("count:*")) {
                redisUtil.deletePrefix("count:*");
            }

            return false;
        } else {
            return true;
        }
    }

    /**
     * 添加订单信息
     *
     * @param HotelOrderMap 用户信息
     * @param token
     * @return
     */
    @Override
    public Dto addHotelOrder(Map<String, Object> HotelOrderMap, String token) {
        ItripUser user = (ItripUser) redisUtil.get(token);
        List<Date> result = null;
        Dto dto = new Dto();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String checkInDate = (String) HotelOrderMap.get("checkInDate");
        String checkOutDate = (String) HotelOrderMap.get("checkOutDate");
        Date CheckInDate = null;
        Date CheckOutDate = null;
        try {
            CheckInDate = format.parse(checkInDate);
            CheckOutDate = format.parse(checkOutDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Long id = (Long) HotelOrderMap.get("id");
        HotelOrderMap.get("count");

        Integer count = new Integer(HotelOrderMap.get("count").toString());
        Long hotelId = new Long(HotelOrderMap.get("hotelId").toString());
        String hotelName = (String) HotelOrderMap.get("hotelName");
        String invoiceHead = null;
        if (HotelOrderMap.get("invoiceHead") != null && !HotelOrderMap.get("invoiceHead").equals("")) {
            invoiceHead = (String) HotelOrderMap.get("invoiceHead");
        }
        Integer invoiceType = new Integer(HotelOrderMap.get("invoiceType").toString());
        Integer isNeedInvoice = null;
        if (HotelOrderMap.get("isNeedInvoice") != null) {
            isNeedInvoice = (Integer) HotelOrderMap.get("isNeedInvoice");
        }
        List linkUser = (List) HotelOrderMap.get("linkUser");
        String noticeEmail = (String) HotelOrderMap.get("noticeEmail");
        String noticePhone = (String) HotelOrderMap.get("noticePhone");
        Integer orderType = new Integer(HotelOrderMap.get("orderType").toString());
        Long roomId = new Long(HotelOrderMap.get("roomId").toString());
        String specialRequirement = null;
        if (HotelOrderMap.get("specialRequirement") != null && !HotelOrderMap.get("specialRequirement").equals("")) {
            specialRequirement = (String) HotelOrderMap.get("specialRequirement");
        }
        ItripOrderInfoVO itripOrderInfoVO = new ItripOrderInfoVO();
        itripOrderInfoVO.setCheckInDate(CheckInDate);
        itripOrderInfoVO.setCheckOutDate(CheckOutDate);
        itripOrderInfoVO.setHotelId(Long.valueOf(hotelId));
        itripOrderInfoVO.setRoomId(Long.valueOf(roomId));
        List<ItripHotelTempStore> store = itripHotelTempStoreMapper.getTempStore(itripOrderInfoVO);
        Integer num = store.get(0).getStore();
        if (num - count >= 0) {
            result = new ArrayList<>();
            Calendar tempStart = Calendar.getInstance();
            tempStart.setTime(CheckInDate);
            Calendar tempEnd = Calendar.getInstance();
            tempEnd.setTime(CheckOutDate);
            while (tempStart.before(tempEnd) || tempStart.equals(tempEnd)) {
                result.add(tempStart.getTime());
                tempStart.add(Calendar.DAY_OF_YEAR, 1);
            }
            Integer days = result.size() - 1;
            if (days <= 0) {
                dto = new Dto();
                dto.setSuccess("false");
                dto.setMsg("退房日期必须大于入住日期");
                return dto;
            }
            StringBuilder linkUserName = new StringBuilder();
            int size = linkUser.size();
            for (int i = 0; i < size; i++) {
                if (i != size - 1) {
                    LinkedHashMap itripUseLinkUser = (LinkedHashMap) linkUser.get(i);
                    linkUserName.append(itripUseLinkUser.get("linkUserName") + ",");
//                    linkUserName.append(linkUser.get(i).getLinkUserName() + ",");
                } else {
                    LinkedHashMap itripUseLinkUser = (LinkedHashMap) linkUser.get(i);
                    linkUserName.append(itripUseLinkUser.get("linkUserName"));
//                    linkUserName.append(linkUser.get(i).getLinkUserName());
                }
            }
            ItripHotelOrder itripHotelOrder = new ItripHotelOrder();
            itripHotelOrder.setId(id);
            itripHotelOrder.setOrderType(orderType);
            itripHotelOrder.setHotelId(hotelId);
            itripHotelOrder.setHotelName(hotelName);
            itripHotelOrder.setRoomId(roomId);
            itripHotelOrder.setCount(count);
            itripHotelOrder.setCheckInDate(CheckInDate);
            itripHotelOrder.setCheckOutDate(CheckOutDate);
            itripHotelOrder.setNoticePhone(noticePhone);
            itripHotelOrder.setNoticeEmail(noticeEmail);
            itripHotelOrder.setSpecialRequirement(specialRequirement);
            itripHotelOrder.setIsNeedInvoice(isNeedInvoice);
            itripHotelOrder.setInvoiceHead(invoiceHead);
            itripHotelOrder.setInvoiceType(invoiceType);
            itripHotelOrder.setLinkUserName(linkUserName.toString());
            itripHotelOrder.setBookingDays(days);
            itripHotelOrder.setCreationDate(new Date());
            itripHotelOrder.setCreatedBy(user.getId());
            itripHotelOrder.setUserId(user.getId());

            if (token.startsWith("token:PC")) {
                itripHotelOrder.setBookType(0);
            } else if (token.startsWith("token:MOBILE")) {
                itripHotelOrder.setBookType(1);
            } else {
                itripHotelOrder.setBookType(2);
            }
            Md5Util Md5 = new Md5Util();
            itripHotelOrder.setOrderStatus(0);
            //生成订单号： 日期+（MD5）（商品IDs+毫秒数+1000000的随机数）
            StringBuilder md5String = new StringBuilder();
            md5String.append(itripHotelOrder.getHotelId());
            md5String.append(itripHotelOrder.getRoomId());
            md5String.append(System.currentTimeMillis());
            md5String.append(Math.random() * 1000000);
            String md5 = Md5.encode(md5String.toString());
            String nums = md5.substring(0, 6);
            //订单编号
            StringBuilder orderNo = new StringBuilder();
            orderNo.append("Z00021");
            orderNo.append(format.format(new Date()));
            orderNo.append(nums);
            itripHotelOrder.setOrderNo(orderNo.toString());
            //计算订单的总金额
            ItripHotelRoom itripHotelRoom = itripHotelRoomMapper.Selectroom(roomId);
            BigDecimal roomPrice = itripHotelRoom.getRoomPrice();
            BigDecimal num1 = new BigDecimal(count * days);
            BigDecimal price = roomPrice.multiply(num1);
            itripHotelOrder.setPayAmount(price);
            Map<String, Object> map = this.itriptxAddItripHotelOrder(itripHotelOrder, linkUser);
            dto.setSuccess("true");
            dto.setMsg("生成订单成功");
            dto.setData(map);
            dto.setErrorCode("0");
        } else {
            dto.setSuccess("false");
            dto.setMsg("无空房");
        }
        return dto;
    }

    /**
     * 添加酒店订单
     *
     * @param itripHotelOrder 酒店订单
     * @param linkUserList    常用联系人
     * @return
     */
    @Override
    public Map<String, Object> itriptxAddItripHotelOrder(ItripHotelOrder itripHotelOrder, List linkUserList) {
        Map<String, Object> map1 = new HashMap<>();
        if (itripHotelOrder != null) {
            int flag = 0;
            if (itripHotelOrder.getId() == null) {
                flag = itripHotelOrderMapper.insertSelective(itripHotelOrder);
                if (redisUtil.hasPreKey("order:*")) {
                    redisUtil.deletePrefix("order:*");
                }
                if (redisUtil.hasPreKey("count:*")) {
                    redisUtil.deletePrefix("count:*");
                }
            } else {
                itripOrderLinkUserMapper.deleteItripOrderLinkUserByOrderId(itripHotelOrder.getId());
                itripHotelOrder.setModifyDate(new Date());
                itripHotelOrderMapper.updateByPrimaryKey(itripHotelOrder);
                if (redisUtil.hasPreKey("order:*")) {
                    redisUtil.deletePrefix("order:*");
                }
            }
            if (flag > 0) {
                ItripHotelOrder itripHotelOrder1 = itripHotelOrderMapper.selectBySelect(itripHotelOrder);
                Long orderId = itripHotelOrder1.getId();
                //添加订单之后还需要往订单与常用联系人关联表中添加记录
                if (orderId > 0) {

                    for (int i = 0; i < linkUserList.size(); i++) {
                        LinkedHashMap itripUseLinkUser = (LinkedHashMap) linkUserList.get(i);
                        ItripOrderLinkUser itripOrderLinkUser = new ItripOrderLinkUser();
                        itripOrderLinkUser.setOrderId(orderId);
                        itripOrderLinkUser.setLinkUserId(new Long(itripUseLinkUser.get("id").toString()));
                        itripOrderLinkUser.setLinkUserName((String) itripUseLinkUser.get("linkUserName"));
                        itripOrderLinkUser.setCreationDate(new Date());
                        itripOrderLinkUser.setCreatedBy(itripHotelOrder.getCreatedBy());
                        itripOrderLinkUserMapper.insertSelective(itripOrderLinkUser);
                    }
                }
                map1.put("id", itripHotelOrder1.getId().toString());
                map1.put("orderNo", itripHotelOrder1.getOrderNo());
                map1.put("checkInDate", itripHotelOrder.getCheckInDate());
                map1.put("checkInDate", itripHotelOrder.getCheckInDate());
                return map1;
            }
        }
        return map1;
    }

    @Transactional
    @Override
    public boolean insertTempByScheduled() {
        List<ItripHotelRoom> rooms = itripHotelRoomMapper.selectHotelIdAndRoomIdByScheduled();
        for (ItripHotelRoom room : rooms) {
            int i = itripHotelTempStoreMapper.insertTemStoreByScheduled(room.getHotelId(), room.getId());
            if (i < 0) {
                try {
                    throw new Exception();
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }

            }
        }
        return true;
    }
}